import send_msg from './_service';

const DBACC_FIND = 'dbacc.find.intranet';

// 查询数据
/*
 * 查询数据
 * @param _action_id 系统参数action_id
 * @param _session_id 系统参数session_id
 * @param spaceid 系统参数spaceid
 * @param systemid 当前项目systemid
 * @param query_mode 查询的模块
 * @param tablename 表名
 * @param fields 字段名
 * @param criteria 条件
 * @param page_no 页码
 * @param page_size 条数
 * @param sort 排序
 * @param sql sql
 */
export default async function dbacc_find(_action_id: string, _session_id: string, spaceid: string, systemid: string, query_mode: number, tablename: string, fields: any, criteria: any, page_no: number, page_size: number, sort: any, sql: string) {
	const msg = [{
		criteria,
		fields,
		page_no,
		page_size,
		query_mode,
		sort,
		spaceid,
		sql,
		systemid,
		tablename
	}];
	const data = await send_msg<Array<{
		tablename: string;
		dataArray: any[];
	}>>(DBACC_FIND, msg, false, false);
	if (data.length > 0) {
		for (const element of data) {
			if (element.tablename === tablename) {
				return element.dataArray;
			}
		}
	}
	return [];
}
